package com.example.zhinongbao.presenter;

import com.example.zhinongbao.contract.IPersonalCenter;
import com.example.zhinongbao.contract.PersonalCenterContact;
import com.example.zhinongbao.entity.UserInfo;

public class PersonalCenterPresenter {
    private PersonalCenterContact personalCenterContact ;
    private IPersonalCenter iPersonalCenter ;
    public PersonalCenterPresenter(PersonalCenterContact contact , IPersonalCenter personalCenter){
        this.personalCenterContact = contact ;
        this.iPersonalCenter = personalCenter ;
    }

    //将用户信息展示到页面上
    public void showMessage(String username){
        UserInfo user = iPersonalCenter.getUserByName(username);
        if (user != null){
            String avatarPath = user.getConcern();
//            String name = user.getUsername();
            int age = user.getAge();
            String address = user.getAddress();
            String id =user.getUser_id();
            String phone =user.getPhone();
            if (avatarPath == null ){
                personalCenterContact.updateAvatar("mine_a.png");
            }else {
                personalCenterContact.updateAvatar(avatarPath);
            }
            if (id == null ){
                personalCenterContact.updateID("未设置");
            }else {
                personalCenterContact.updateID(id);
            }
            if (age == 0 ){
                personalCenterContact.updateAge("未设置");
            }else {
                personalCenterContact.updateAge(""+age);
            }
            if (address == null ){
                personalCenterContact.updateAddress("未设置");
            }else {
                personalCenterContact.updateAddress(address);
            }
            if (phone == null ){
                personalCenterContact.updatePhone("未设置");
            }else {
                personalCenterContact.updatePhone(phone);
            }
            if (username == null ){
                personalCenterContact.updateName("未设置");
            }else {
                personalCenterContact.updateName(username);
            }

        }
    }
    public void updateAvatar(String username , String avatarPath){
        iPersonalCenter.updateConcern(username,avatarPath);
    }
    public void updateID(String username , String newuserid){
        iPersonalCenter.updateID(username, newuserid);
    }
    public void updateAge(String username , String newAge){
        iPersonalCenter.updateAge(username, newAge);
    }
    public void updateAddress(String username , String newLocal){
        iPersonalCenter.updateAddress(username, newLocal);
    }
    public void updatePhone(String username , String newPhone){
        iPersonalCenter.updatePhone(username, newPhone);
    }
}
